package bpm.domain.document;

import java.io.Serializable;
import java.util.Date;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class TemplateView implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public Integer id;
	public Integer version;
	public String name;
	public String type;
	public Integer documentDefinitionId;
	public String documentDefinistionName;
	public String creatorId;
	public String description;
	
	public Date createTime;
	public Date lastUpdateTime;
	
	public byte[] previewImage;
	public byte[] content;
	
	
	public boolean hasContent;
	public boolean hasPreviewImage;
	
	public TemplateView () {}
	public TemplateView (Template template) {
		if(template != null) {
			this.id = template.getId();
			this.version = template.getVersion();
			this.name = template.getName();
			this.type = template.getType().name();
			if(template.getDocumentDefinition() != null) {
				this.documentDefinitionId = template.getDocumentDefinition().getId();
				this.documentDefinistionName = template.getDocumentDefinition().getName();
			}
			this.description = template.getDescription();
			if(template.getCreator() != null) {
				this.creatorId = template.getCreator().getId();
			}
			this.createTime = template.getCreateTime();
			this.lastUpdateTime = template.getLastUpdateTime();
			
			if(template.getContent() != null) {
				this.hasContent = true;
			} else {
				this.hasContent = false;
			}
			if(template.getPreviewImage() != null) {
				this.hasPreviewImage = true;
			} else {
				this.hasPreviewImage = false;
			}
			
			this.content = template.getContent();
			this.previewImage = template.getPreviewImage();
		}
	}
}
